package com.ruoyi.web.controller;


import com.ruoyi.common.core.domain.R;
import com.ruoyi.web.domain.DyLoginRes;
import com.ruoyi.web.domain.WechatLoginRes;
import com.ruoyi.web.service.ThirdPartLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
@Api("第三方登录")
@RestController
public class ThirdPartLogin {

    @Autowired
    private ThirdPartLoginService thirdPartLoginService;

    /**
     * 微信登录
     * @param code 登录code
     * @return
     */
    @ApiOperation("微信登录")
    @PostMapping("/wechatLogin")
    public R wechatLogin(String code){
        WechatLoginRes wechatLoginRes = thirdPartLoginService.jscodeToSession(code);
        if(wechatLoginRes.getErrCode() == 0){
            return R.ok(wechatLoginRes);
        }
        return R.fail(wechatLoginRes,"抖音登录失败");
    }

    @ApiOperation("抖音登录")
    @PostMapping("/douyinLogin")
    public R douyinLogin(String code,String anonymousCode){
        DyLoginRes dyLoginRes = thirdPartLoginService.jscodeToSession(code,anonymousCode);
        if(dyLoginRes.getErrNo() == 0){
            return R.ok(dyLoginRes);
        }
        return R.fail(dyLoginRes,"抖音登录失败");
    }


}
